const { mongoose, db } = require('../utils/mongoose')
let schema = mongoose.Schema({
    id:{type:String,required:true},
    hobby:{type:String,required:true},
    desc:{type:String,required:true}
})

let Collection = mongoose.model('hobbies', schema)


//新增
const createHobby=(data)=>{
    let model = new Collection(data)
    return model.save()
        .then(res => res)
        .catch(err => {
            console.log(err);
            return false;
        })
}
//查询
// .sort({'date':-1})//按插入时间倒序排列
// date:{$gte: sDate, $lte: eDate}
const findHobbies=(data)=>{
    return Collection.find(data).sort()
        .then(res=>res)
        .catch(err=>{
            console.log(err);
            return false;
        })
}
//删除
let delHobby = (query = {}) => {
    return Collection.deleteOne(query)
        .then(res=>res)
        .catch(err=>{
            console.log(err)
            return false;
        })
}
module.exports={
    createHobby,
    findHobbies,
    delHobby
}